home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Games / net3d-0.08 / vtoc.c < prev   
C/C++ Source or Header  |  1995-06-22  |  1KB  |  64 lines

  1. /* vtoc.c
  2.  *
  3.  * A short program for converting .v files into a .c file containing
  4.  * an array of strings corresponding to the lines in the .v file.
  5.  */
  6. #include "net3d.h"
  7.  
  8. int main(int argc, char **argv)
  9. {
  10. int i;
  11.  
  12. if (argc == 1) {
  13.     printf("you must give a filename(s) to convert\n");
  14.     exit(1);
  15.     }
  16.  
  17. for(i=1; i<argc; i++) {
  18.     FILE *fp;
  19.     char combuf[100];
  20.     char *dot;
  21.     char *name;
  22.  
  23.  
  24.     /* pipe through cpp */
  25.     sprintf(combuf,"%s %s",CPPPATH,argv[i]);
  26.     fp=popen(combuf,"r");
  27.  
  28.     /* skip leading dots */
  29.     for(name=argv[i]; *name=='.' || *name=='/'; name++)
  30.         ;
  31.  
  32.     /* get rid of dot */
  33.     dot = strchr(name,'.');
  34.     if (dot)
  35.         *dot = '\0';
  36.  
  37.     printf("char *%s[] = {\n",name);
  38.  
  39.     /* read a line at a time from the file */
  40.     while(!feof(fp)) {
  41.         char buf[600];
  42.         fgets(buf,600,fp);
  43.         if (feof(fp))
  44.             break;
  45.         if (buf[0] != '#') {
  46.             int j;
  47.             printf("\"");
  48.             for(j=0; j<strlen(buf)-1; j++) {
  49.                 if (buf[j] == '\"')
  50.                     printf("\\\"");
  51.                 else
  52.                     putchar(buf[j]);
  53.                 }
  54.             printf("\",\n");
  55.             }
  56.         }
  57.     printf("(char *)0,\n");
  58.     printf("};\n");
  59.     pclose(fp);
  60.     }
  61.    return(0);
  62. }
  63.  
  64.